package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.voip.GoodsClassify;
import com.base.service.GoodsClassifyService;
import com.base.service.LogsService;
import com.base.utils.IP;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;

/**
 * 添加商品分类信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class add_GoodsClassify {

	@Autowired
	private LogsService logsService; // log日志
	@Autowired
	private GoodsClassifyService goodsClassifyService; // 商品分类信息

	// 添加商品分类信息
	@RequestMapping(value = "/toAddGoodsClassify", method = RequestMethod.POST)
	public @ResponseBody int toAddGoodsClassify(HttpServletRequest request, GoodsClassify goodsClassify) throws Exception {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录
		goodsClassify.setId(Produce.getUUID()); // 设置参数 主键ID
		goodsClassify.setAgentid(userid); // 代理商ID
		goodsClassify.setCreatetime(Produce.getNowDate()); // 创建时间
		goodsClassify.setDatastatus((byte) 1); // 数据状态
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置商品分类信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return goodsClassifyService.insertSelective(goodsClassify); // 添加
	}
}
